﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/AdminMasterPage.master" Inherits="System.Web.Mvc.ViewPage<SHDQGSWEB.Models.Product>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Create</h2>
    <script type="text/JavaScript">
        
        function deleteClicked() {
            var container = document.getElementById("inputsPlace");
            var inputElls = container.getElementsByTagName("input");
            var inputs = [];

            for (var i = 0; i < inputElls.length; i++) {
                inputs.push(inputElls[i]);
            }

            for (var i = 0; i < inputs.length; i++) {
                var inputElement = inputs[i];
                if (inputElement.type == "checkbox" && inputElement.checked) {
                    var number = inputElement.id.replace(/^check(\d+)/, "$1");
                    var div = document.getElementById("div" + number);

                    div.parentNode.removeChild(div);
                }
            }
        }

        function addClicked() {
            var container = document.getElementById("inputsPlace");
            var inputs = container.getElementsByTagName("input");
            var number = "1";

            for (var i = 0; i < inputs.length; i++) {
                var inputElement = inputs[i];
                if (inputElement.type == "checkbox") {
                    number = (parseInt(inputElement.id.replace(/^check(\d+)/, "$1")) + 1).toString();
                }
            }

            var newDiv = document.createElement("DIV");
            newDiv.id = "div" + number;
            container.appendChild(newDiv);

            var newCheck = document.createElement("INPUT");
            newCheck.id = "check" + number;
            newCheck.type = "checkbox";
            newDiv.appendChild(newCheck);

            var newInput = document.createElement("INPUT");
            newInput.name = "myFile" + number;
            newInput.type = "file";
            newInput.style.marginLeft = "20px";
            newDiv.appendChild(newInput);
        }
    </script>
    <% using (Html.BeginForm("Create", "ProductAdmin", FormMethod.Post, new { enctype = "multipart/form-data" })) {%>
        <%= Html.ValidationSummary(true) %>

        <fieldset>
            <legend>Fields</legend>

            <div class="editor-label">
                <%= Html.Label("产品名称") %>
            </div>
            <div class="editor-field">
                <%= Html.TextBoxFor(model => model.Name) %>
                <%= Html.ValidationMessageFor(model => model.Name) %>
            </div>
            <div class="editor-label">
                <%= Html.Label("请选择文件：") %>
            </div>
            <input type="button" value="增加文件" onclick="addClicked();" />
            <input type="button" value="删除选中文件" onclick="deleteClicked();" />
            <div id="inputsPlace">
                <div id="div1">
                    <input type="checkbox" id="check1" />
                    <input type="file" name="myFile1" style="margin-left:20px;" />
                </div>
            </div>              
            <div class="editor-label">
                <%= Html.LabelFor(model => model.Introduction) %>
            </div>
            <div class="editor-field">
                <%= Html.TextBoxFor(model => model.Introduction) %>
                <%= Html.ValidationMessageFor(model => model.Introduction) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.DisplayMode) %>
            </div>
            <div class="editor-field">
                <%= Html.TextBoxFor(model => model.DisplayMode) %>
                <%= Html.ValidationMessageFor(model => model.DisplayMode) %>
            </div>
            
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>

    <% } %>

    <div>
        <%= Html.ActionLink("Back to List", "Index") %>
    </div>

</asp:Content>

